/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package uimigration.WidgetsModel.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.util.InternalEList;

import uimigration.Plateform.Device;
import uimigration.WidgetsModel.APIModel;
import uimigration.WidgetsModel.Widget;
import uimigration.WidgetsModel.WidgetsModelPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>API Model</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link uimigration.WidgetsModel.impl.APIModelImpl#getContainsList <em>Contains</em>}</li>
 *   <li>{@link uimigration.WidgetsModel.impl.APIModelImpl#getApiName <em>Api Name</em>}</li>
 *   <li>{@link uimigration.WidgetsModel.impl.APIModelImpl#getInstallOnList <em>Install On</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class APIModelImpl extends EObjectImpl implements APIModel {
	/**
	 * The cached value of the '{@link #getContainsList() <em>Contains</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getContainsList()
	 * @generated NOT
	 * @ordered
	 */
	protected EList<Widget> contains;

	/**
	 * The empty value for the '{@link #getContains() <em>Contains</em>}' array accessor.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getContains()
	 * @generated
	 * @ordered
	 */
	protected static final Widget[] CONTAINS_EEMPTY_ARRAY = new Widget[0];

	/**
	 * The default value of the '{@link #getApiName() <em>Api Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getApiName()
	 * @generated
	 * @ordered
	 */
	protected static final String API_NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getApiName() <em>Api Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getApiName()
	 * @generated
	 * @ordered
	 */
	protected String apiName = API_NAME_EDEFAULT;

	/**
	 * The cached value of the '{@link #getInstallOn() <em>Install On</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getInstallOn()
	 * @generated NOT
	 * @ordered
	 */
	protected EList<Device> installOn;

	/**
	 * The empty value for the '{@link #getInstallOn() <em>Install On</em>}' array accessor.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getInstallOn()
	 * @generated
	 * @ordered
	 */
	protected static final Device[] INSTALL_ON_EEMPTY_ARRAY = new Device[0];

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected APIModelImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected EClass eStaticClass() {
		return WidgetsModelPackage.Literals.API_MODEL;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public EList<Widget> getContains() {
		if (contains == null) {
			contains = new EObjectContainmentEList<Widget>(Widget.class, this,
					WidgetsModelPackage.API_MODEL__CONTAINS);
		}
		return contains;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Widget getContains(int index) {
		return (Widget) getContainsList().get(index);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getContainsLength() {
		return contains == null ? 0 : contains.size();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setContains(Widget[] newContains) {
		((BasicEList<Widget>) getContainsList()).setData(newContains.length,
				newContains);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setContains(int index, Widget element) {
		getContainsList().set(index, element);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public EList<Widget> getContainsList() {
		if (contains == null) {
			contains = new EObjectContainmentEList<Widget>(Widget.class, this,
					WidgetsModelPackage.API_MODEL__CONTAINS);
		}
		return contains;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getApiName() {
		return apiName;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setApiName(String newApiName) {
		String oldApiName = apiName;
		apiName = newApiName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET,
					WidgetsModelPackage.API_MODEL__API_NAME, oldApiName,
					apiName));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public EList<Device> getInstallOn() {
		if (installOn == null) {
			installOn = new EObjectContainmentEList<Device>(Device.class, this,
					WidgetsModelPackage.API_MODEL__INSTALL_ON);
		}
		return installOn;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Device getInstallOn(int index) {
		return (Device) getInstallOnList().get(index);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getInstallOnLength() {
		return installOn == null ? 0 : installOn.size();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setInstallOn(Device[] newInstallOn) {
		((BasicEList<?>) getInstallOnList()).setData(newInstallOn.length,
				newInstallOn);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setInstallOn(int index, Device element) {
		getInstallOnList().set(index, element);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Device> getInstallOnList() {
		if (installOn == null) {
			installOn = new EObjectContainmentEList<Device>(Device.class, this,
					WidgetsModelPackage.API_MODEL__INSTALL_ON);
		}
		return installOn;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public NotificationChain eInverseRemove(InternalEObject otherEnd,
			int featureID, NotificationChain msgs) {
		switch (featureID) {
		case WidgetsModelPackage.API_MODEL__CONTAINS:
			return ((InternalEList<Widget>) getContains()).basicRemove(
					otherEnd, msgs);
		case WidgetsModelPackage.API_MODEL__INSTALL_ON:
			return ((InternalEList<Device>) getInstallOn()).basicRemove(
					otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
		case WidgetsModelPackage.API_MODEL__CONTAINS:
			return getContainsList();
		case WidgetsModelPackage.API_MODEL__API_NAME:
			return getApiName();
		case WidgetsModelPackage.API_MODEL__INSTALL_ON:
			return getInstallOnList();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
		case WidgetsModelPackage.API_MODEL__CONTAINS:
			getContainsList().clear();
			getContainsList().addAll((Collection<? extends Widget>) newValue);
			return;
		case WidgetsModelPackage.API_MODEL__API_NAME:
			setApiName((String) newValue);
			return;
		case WidgetsModelPackage.API_MODEL__INSTALL_ON:
			getInstallOnList().clear();
			getInstallOnList().addAll((Collection<? extends Device>) newValue);
			return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void eUnset(int featureID) {
		switch (featureID) {
		case WidgetsModelPackage.API_MODEL__CONTAINS:
			getContainsList().clear();
			return;
		case WidgetsModelPackage.API_MODEL__API_NAME:
			setApiName(API_NAME_EDEFAULT);
			return;
		case WidgetsModelPackage.API_MODEL__INSTALL_ON:
			getInstallOnList().clear();
			return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean eIsSet(int featureID) {
		switch (featureID) {
		case WidgetsModelPackage.API_MODEL__CONTAINS:
			return contains != null && !contains.isEmpty();
		case WidgetsModelPackage.API_MODEL__API_NAME:
			return API_NAME_EDEFAULT == null ? apiName != null
					: !API_NAME_EDEFAULT.equals(apiName);
		case WidgetsModelPackage.API_MODEL__INSTALL_ON:
			return installOn != null && !installOn.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String toString() {
		if (eIsProxy())
			return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (apiName: ");
		result.append(apiName);
		result.append(')');
		return result.toString();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated not
	 */

	public EList<Device> getDevices() {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */

	@Override
	public Widget findWidget(String name) {
		if (contains != null&&name!=null)
			for (Widget w : getContainsList())
			{	if ( w.getName()!=null&&w.getName().compareTo(name) == 0)
					return (Widget) EcoreUtil.copy(w);
				else if(w.getContainsWidget()!=null && w.getContainsWidget().size()>0){
					for(Widget cw : w.getContainsWidget())
						if( cw.getName()!=null && cw.getName().compareTo(name)==0)
							return (Widget) EcoreUtil.copy(cw);
				}
			}
		return null;
	}

} //APIModelImpl
